package com.yc.cloud.admin.controller;

import com.yc.cloud.admin.dto.request.HwCameraTimeSlotCreateReqDTO;
import com.yc.cloud.admin.dto.request.HwCameraTimeSlotQueryReqDTO;
import com.yc.cloud.admin.dto.request.HwCameraTimeSlotUpdateReqDTO;
import com.yc.cloud.admin.service.HwCameraTimeSlotService;
import com.yc.cloud.admin.vo.HwCameraTimeSlotVo;
import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.common.orm.CommonPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 摄像头时间段配置 前端控制器
 * </p>
 *
 * @author kinggu
 * @since 2025-10-14
 */
@RestController
@Api(tags = "摄像头时间段配置管理")
@RequestMapping("/hw-camera-timeslots")
public class HwCameraTimeSlotController {

    @Resource
    private HwCameraTimeSlotService hwCameraTimeSlotService;

    @ApiOperation("创建时间段配置")
    @PostMapping
    public ResponseResult<HwCameraTimeSlotVo> create(@Validated @RequestBody HwCameraTimeSlotCreateReqDTO createReqDTO) {
        HwCameraTimeSlotVo newVo = hwCameraTimeSlotService.create(createReqDTO);
        if (newVo != null) {
            return ResponseResult.success(newVo);
        }
        return ResponseResult.failed("创建失败");
    }

    @ApiOperation("更新时间段配置")
    @PutMapping("/{id}")
    public ResponseResult<HwCameraTimeSlotVo> update(@PathVariable("id") Long id, @Validated @RequestBody HwCameraTimeSlotUpdateReqDTO updateReqDTO) {
        updateReqDTO.setId(id);
        HwCameraTimeSlotVo updatedVo = hwCameraTimeSlotService.update(updateReqDTO);
        if (updatedVo != null) {
            return ResponseResult.success(updatedVo);
        }
        return ResponseResult.failed("更新失败");
    }

    @ApiOperation("删除时间段配置")
    @DeleteMapping("/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {
        boolean success = hwCameraTimeSlotService.delete(id);
        if (success) {
            return ResponseResult.success(true);
        }
        return ResponseResult.failed("删除失败");
    }

    @ApiOperation("获取时间段配置详情")
    @GetMapping("/{id}")
    public ResponseResult<HwCameraTimeSlotVo> getById(@PathVariable("id") Long id) {
        return ResponseResult.success(hwCameraTimeSlotService.getVOById(id));
    }

    @ApiOperation("分页查询时间段配置")
    @GetMapping
    public ResponseResult<CommonPage<HwCameraTimeSlotVo>> list(@Validated HwCameraTimeSlotQueryReqDTO queryReqDTO) {
        return ResponseResult.success(hwCameraTimeSlotService.list(queryReqDTO));
    }
}

